import Ember from 'ember';
import config from 'game-front/config/environment';

export default Ember.Service.extend({
	operationItems:[ 'onMenuShareTimeline', 'onMenuShareAppMessage',
		'onMenuShareQQ', 'onMenuShareWeibo', 'closeWindow',
		'hideMenuItems', 'showOptionMenu', 'showAllNonBaseMenuItem',
		'chooseImage', 'previewImage', 'uploadImage', 'downloadImage',
		'closeWindow', 'checkJsApi',
		'openLocation',
		'getLocation', 'scanQRCode', 'chooseWXPay' ],

	config(shareLink) {
		var operationItems = this.get("operationItems");
		Ember.$.ajax({
			method: "GET",
			url: config.apiBase + "wechat/config",
			data: {url:window.location.href},
			contentType:"application/json",
			dataType:"json"
		}) .done(function(resp) {
			wx.config($.extend(resp, {debug:false, jsApiList:operationItems}));
			wx.ready(function() {
				wx.onMenuShareTimeline(shareLink);
				wx.onMenuShareAppMessage(shareLink);
				wx.onMenuShareQQ(shareLink);
			});
		});
	},
	createQR(userId) {
		Ember.$.ajax({
			method: "GET",
			url:"/app/index.php?i=4&c=entry&do=util&m=ewei_shop&p=createQR&content=guanzhu",
			data: {openid:userId}
		}) .done(function(resp) {
			console.log(resp);
		});
	},
	reward(userId) {
		Ember.$.ajax({
			method: "GET",
			url: config.apiBase + "members/share",
			data: {userId:userId},
			contentType:"application/json",
			dataType:"json"
		}) .done(function(resp) {
			console.log(resp);
		});
	}
});
